import requests

#cookie导入，兼容py2,py3

try:
	import cookielib
except:
	import http.cookiejar as cookielib

import re

agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
headers={
	"Host":"www.zhihu.com",
	"Referer":"ttps://www.zhihu.com",
	"User-Agent":agent
}

session=requests.session()
session.cookies=cookielib.LWPCookieJar(filename="cookies.txt")


def is_login():
	# 通过订单页面，判断是否登录
	response = session.get("http://www.ixuea.com/orders", headers=headers, allow_redirects=False)

	if response.status_code==200:
		print("已经登录")
	else:
		print("未登录")

def get_xsrf():
	# response=requests.get("https://www.zhihu.com/",headers=headers)
	# print(response.text)

	#这里匹配我们官网
	text='<meta name="csrf-token" content="3KFqJDWakeTl8VMeXQShnRHz5Iymm78TpchVGjdN6/GRP/34WW313xT0r4R+Z0GL0tbRxTjlPKZvKZW5B6c1EQ==" />'
	match_result=re.match('.*meta name="csrf-token" content="(.*?)" />',text)
	if match_result:
		print(match_result.group(1))
	return ""

def zhihu_login(username,password):
	#知乎登录

	#判断是手机号函数邮箱
	if re.match("^1\d{10}",username):
		print("手机号登录")
		post_url=""
		post_data={

		}

		response_text=session.post("url",data=post_data,headers=headers)

		session.cookies.save()

# get_xsrf()
is_login()